﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using CodeStash.Models.TagCloud;
using CodeStash.Services;




namespace CodeStash.Controllers
{
    public abstract class BaseTagCloudEnabledController : Controller
    {
        private readonly ITagCloudService tagCloudService;

        public BaseTagCloudEnabledController(ITagCloudService tagCloudService)
        {
            this.tagCloudService = tagCloudService;
        }


        public void RenderAndCalculateTagCloud()
        {
            Random rand = new Random();

            IEnumerable<TagCategoryModel> tags = this.tagCloudService.CreateTagCloud();
            if (tags.Any())
            {
                ViewData["TagCloud"] = tags.Take(10);
            }
            else
                ViewData["TagCloud"] = new List<TagCategoryModel>();

            ViewData["Rand"] = rand;

        }
    }
}
